<?php
namespace app\api\model;

use think\Db;
use think\Model;

class UserModel extends Model
{
    function repassword($userid, $oldpassword, $newpassword) {
        $user = db('user')->where('userid',$userid)->find();
        if ($user['password'] == md5($oldpassword)) {
            $result = db('user')->where('userid',$userid)->update(['password' => md5($newpassword)]);
            return ['success'=>$result];
        }else {
            return ['success'=>0];
        }
    }

    //TODO 上传头像
    function updateAvatar($userid,$picture) {
        $result = db('user')->where('userid',$userid)->update(['picture' => $picture]);
        return ['success'=>$result];
    }

    function updateNickname($userid, $nickname) {
        $result = db('user')->where('userid',$userid)->update(['nickname' => $nickname]);
        return ['success'=>$result];
    }

    function  login($username, $password) {
        $result = db('user')->where('username', $username)->where('password', md5($password))->find();
        return $result;
    }
}